home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / Newton Platform Info / Newton 2.0 Sample Code / NewtApp / Checkbook-6 / Checkbook.text < prev    next >
Encoding:
Text File  |  1996-02-28  |  24.7 KB  |  911 lines  |  [TEXT/MPS ]

  1. // Text of project Checkbook written on 2/28/96 at 7:00 PM
  2. // Beginning of text file Constants.f
  3. /*
  4. **      Newton Developer Technical Support Sample Code
  5. **
  6. **      Checkbook, a complete NewtApp sample
  7. **
  8. **      by Neil Rhodes, Calliope &
  9. **          Newton Developer Technical Support
  10. **
  11. **      Copyright © 1994-6 by Apple Computer, Inc.  All rights reserved.
  12. **
  13. **      You may incorporate this sample code into your applications without
  14. **      restriction.  This sample code has been provided "AS IS" and the
  15. **      responsibility for its operation is 100% yours.  You are not
  16. **      permitted to modify and redistribute the source as "DTS Sample Code."
  17. **      If you are going to re-distribute the source, we require that you
  18. **      make it clear in the source that the code was descended from
  19. **      Apple-provided sample code, but that you've made changes.
  20. */
  21.  
  22.  
  23. OpenResFile(HOME & "Icons.rsrc");
  24. DefConst('kReconciledIcon, GetPictAsBits("Reconcile", nil));
  25. DefConst('kSmallCheckIcon, GetPictAsBits("SmallCheck", nil));
  26. CloseResFile();
  27.  
  28. DefConst( 'kPrefsTemplate, {autoDate: nil,
  29.                             autoCheckNum: nil});
  30.  
  31. // Modify these numbers to do testing
  32. constant kMaxWidth := 320;
  33. constant kMaxHeight := 320;
  34.  
  35. constant kMinWidth := 200;
  36. constant kMinHeight := 200;
  37.  
  38. // Define data symbols (used for routing)
  39. constant kCheckClassSym             := '|Check:Checkbook:PIETraining|;
  40. constant kCheckFrameFormatSym         := '|FrameFormat:Checkbook:PIETraining|;
  41. constant kCheckPrintFormatSym         := '|ViewFormat:Checkbook:PIETraining|;
  42.  
  43. // Define a 'routing format' to handle frames (beam, mail, etc)
  44. // By default, protoFrameFormat handles text also; override 'dataTypes to change that.
  45. // Register a separate protoPrintFormat (see the allViewDefs slot in the base view)
  46. // if you want to support print and fax.
  47. DefConst('kCheckFrameFormat, {
  48.     _proto: protoFrameFormat,
  49.     name: "Check frame Format",
  50.     symbol: kCheckFrameFormatSym,
  51.     TextScript: func(item, target)
  52.         begin
  53.             // ... export text if possible.
  54.             // if format.textScript isn't present but a dataDef is, the datadef's
  55.             // textscript will be used to export the text
  56.             
  57.             local string := "Check" & target.number;
  58.             if target.date then
  59.                 string := string && "\nDate" && datentime(target.date);
  60.             if target.payee then
  61.                 string := string && "\nto" && target.payee;
  62.             if target.amount then
  63.                 string := string && "\n$" & formattednumberstr(target.amount, "%.2f");
  64.  
  65.             if target.reconciled then
  66.                 string := string & "\nReconciled";
  67.             else
  68.                 string := string & "\nUnreconciled";
  69.  
  70.             if target.memo then
  71.                 string := string && "\nMemo: " && target.memo;
  72.  
  73.             string;
  74.         end,
  75.         
  76.     SetupItem: func(item, targetInfo)
  77.         begin
  78.             // set up the routing item if necessary
  79.             inherited:?SetupItem(item, targetInfo);
  80.  
  81.             local string := "Check" && targetInfo.target.number;
  82.             if targetInfo.target.payee then
  83.                 string := string && "to" && targetInfo.target.payee;
  84.             
  85.             item.title := string
  86.         end;
  87.         
  88.     });
  89. // End of text file Constants.f
  90. // Beginning of file protoCheckAllButton
  91.  
  92. // Before Script for "protoCheckAllButton"
  93. // Copyright ©1995 Apple Computer, Inc.  All rights reserved.
  94.  
  95. // This file shows how to create a simple button which does a "check all"
  96. // for an overview.
  97.  
  98.  
  99. protoCheckAllButton :=
  100.     {viewBounds: {left: 7, top: 0, right: 33, bottom: 13},
  101.      buttonClickScript:
  102.        func()
  103.            if currentLayout = 'overView then
  104.                begin
  105.                    For i:=0 to (layout.numLines-1) do
  106.                        layout:SelectItem(i);
  107.                    layout:Retarget(true);
  108.                end;,
  109.      icon: GetPictAsBits("checkAll", nil),
  110.      debug: "protoCheckAllButton",
  111.      _proto: @198
  112.     };
  113.  
  114.  
  115. constant |layout_protoCheckAllButton| := protoCheckAllButton;
  116. // End of file protoCheckAllButton
  117. // Beginning of file New Button.t
  118. _view000 :=
  119.     {
  120.      buttonClickScript:
  121.        func()
  122.            base:NewCheck();,
  123.      text: "New",
  124.      viewBounds: {left: 7, top: 0, right: 50, bottom: 13},
  125.      _proto: @226
  126.     };
  127.  
  128.  
  129. constant |layout_New Button.t| := _view000;
  130. // End of file New Button.t
  131. // Beginning of file Default View.t
  132.  
  133. // Before Script for "_view001"
  134. // Copyright ©1995 Apple Computer, Inc.  All rights reserved.
  135.  
  136.  
  137. _view001 :=
  138.     {viewBounds: {left: 0, top: 20, right: 0, bottom: -20},
  139.      masterSoupSlot:
  140.        // refers to a slot in the allSoups frame
  141.        // see newtApplication.allsoups in CheckBase.t
  142.        'checkSoup,
  143.      name: "Check",
  144.      viewJustify: 240,
  145.      forceNewEntry: nil,
  146.      menuLeftButtons:
  147.        // these will replace the menuLeftButtons in the newtStatusBar in the
  148.        // base view, because the 'statusBarSet in the base view is set to the
  149.        // declared name of the status bar.
  150.        // Note that we do not replace the menuRightButtons.
  151.        [
  152.            newtInfoButton,
  153.            {    
  154.                _proto: protoRecToggle,
  155.                _recogPopup: ['recogText, 'recogInkText, 'pickseparator, 'recToggleSettings],
  156.            },
  157.            GetLayout("New Button.t"),
  158.        ],
  159.      _proto: @402
  160.     };
  161.  
  162. entryView :=
  163.     {viewBounds: {left: 0, top: 0, right: 0, bottom: 0},
  164.      viewJustify: 240,
  165.      DoInit:
  166.        func(symbol, textView)
  167.            begin
  168.                local s := GetUserConfig(symbol);
  169.                
  170.                if not s then
  171.                    s := "";
  172.                SetValue(self.(textView), 'text, Clone(s));
  173.            end,
  174.      viewSetupDoneScript:
  175.        func()
  176.        begin
  177.            :DoInit('name, 'theName);
  178.            :DoInit('address, 'theAddress);
  179.            :DoInit('cityZip, 'theCityZip);
  180.            inherited:?viewSetupDoneScript();
  181.        end,
  182.      viewSetupChildrenScript:
  183.        func()
  184.            // don't want anything to show up if the folder is empty
  185.            if not target then
  186.                stepChildren := nil;,
  187.      debug: "entryView",
  188.      _proto: @406
  189.     };
  190. AddStepForm(_view001, entryView);
  191.  
  192. theName :=
  193.     {text: "",
  194.      viewBounds: {left: 0, top: 0, right: 110, bottom: 14},
  195.      debug: "theName",
  196.      _proto: @218
  197.     };
  198. AddStepForm(entryView, theName);
  199. StepDeclare(entryView, theName, 'theName);
  200.  
  201.  
  202.  
  203. theAddress :=
  204.     {text: "",
  205.      viewBounds: {left: 0, top: 0, right: 0, bottom: 14},
  206.      viewJustify: 8398384,
  207.      debug: "theAddress",
  208.      _proto: @218
  209.     };
  210. AddStepForm(entryView, theAddress);
  211. StepDeclare(entryView, theAddress, 'theAddress);
  212.  
  213.  
  214.  
  215. theCityZip :=
  216.     {text: "",
  217.      viewBounds: {left: 0, top: 0, right: 0, bottom: 14},
  218.      viewJustify: 8398336,
  219.      debug: "theCityZip",
  220.      _proto: @218
  221.     };
  222. AddStepForm(entryView, theCityZip);
  223. StepDeclare(entryView, theCityZip, 'theCityZip);
  224.  
  225.  
  226.  
  227. number :=
  228.     {viewBounds: {left: -100, top: 27, right: -5, bottom: 53},
  229.      path: 'number,
  230.      viewJustify: 32,
  231.      flavor:
  232.        {
  233.            _proto: newtIntegerFilter,
  234.            recConfig: nil,    // prevent ink
  235.        },
  236.      debug: "number",
  237.      _proto: @423
  238.     };
  239. AddStepForm(entryView, number);
  240.  
  241.  
  242.  
  243. amount :=
  244.     {viewBounds: {left: 4, top: 0, right: 35, bottom: 26},
  245.      path: 'amount,
  246.      viewJustify: 134225920,
  247.      flavor:
  248.        {
  249.            _proto: newtNumberFilter,
  250.            format: kFnBasicCurrency,
  251.            recConfig: nil,    // prevent ink
  252.        };,
  253.      debug: "amount",
  254.      _proto: @423
  255.     };
  256. AddStepForm(entryView, amount);
  257.  
  258.  
  259.  
  260. date :=
  261.     {viewBounds: {left: -65, top: 0, right: -5, bottom: 26},
  262.      path: 'date,
  263.      viewJustify: 67125280,
  264.      flavor:
  265.        {
  266.            _proto: newtDateFilter,
  267.            recConfig: nil,    // prevent ink
  268.        };,
  269.      debug: "date",
  270.      _proto: @424
  271.     };
  272. AddStepForm(entryView, date);
  273.  
  274.  
  275.  
  276. payee :=
  277.     {viewBounds: {left: 5, top: 0, right: -5, bottom: 30},
  278.      path: 'payee,
  279.      label: "Payee",
  280.      viewJustify: 8240,
  281.      debug: "payee",
  282.      _proto: @422
  283.     };
  284. AddStepForm(entryView, payee);
  285.  
  286.  
  287.  
  288. memo :=
  289.     {viewBounds: {left: 5, top: 0, right: -5, bottom: 30},
  290.      path: 'memo,
  291.      label: "Memo",
  292.      viewJustify: 8240,
  293.      debug: "memo",
  294.      _proto: @422
  295.     };
  296. AddStepForm(entryView, memo);
  297.  
  298.  
  299.  
  300. reconciled :=
  301.     {path: 'reconciled,
  302.      viewJustify: 8246,
  303.      viewBounds: {left: 5, top: 0, right: -5, bottom: 30},
  304.      TargetData:
  305.        func()
  306.            if target and path then
  307.                if target.(path) then
  308.                    "Reconciled"
  309.                else
  310.                    "Unreconciled",
  311.      debug: "reconciled",
  312.      _proto: @414
  313.     };
  314. AddStepForm(entryView, reconciled);
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321. constant |layout_Default View.t| := _view001;
  322. // End of file Default View.t
  323. // Beginning of file Overview.t
  324.  
  325. // Before Script for "overview"
  326. // Copyright ©1995 Apple Computer, Inc.  All rights reserved.
  327.  
  328.  
  329. overview :=
  330.     {viewBounds: {left: 0, top: 20, right: 0, bottom: -20},
  331.      masterSoupSlot:
  332.        'checkSoup    // which soup to get info from.
  333.        ,
  334.      name: "Overview",
  335.      viewJustify: 240,
  336.      viewFormat: 336,
  337.      forceNewEntry:
  338.        nil    // don't create a new item if folder is empty
  339.        ,
  340.      viewSetupChildrenScript:
  341.        func()
  342.            begin
  343.                if not smallCheckShape then
  344.                    begin
  345.                        // create shapes from bitmaps for the icons in each item
  346.                        smallCheckShape := OffsetShape(MakeShape(kSmallCheckIcon), 0, 5);
  347.                        reconciledShape := OffsetShape(MakeShape(kReconciledIcon), 0, 3);
  348.                    end;
  349.                inherited:?viewSetupChildrenScript();
  350.            end,
  351.      lineHeight: 17,
  352.      smallCheckShape:
  353.        nil    // viewSetupChildrenScript will create the shape from a bitmap (see Constants.f)
  354.        ,
  355.      reconciledShape:
  356.        nil    // viewSetupChildrenScript will create the shape from a bitmap (see Constants.f)
  357.        ,
  358.      menuLeftButtons:
  359.        // these will replace the menuLeftButtons in the newtStatusBar in the
  360.        // base view, because the 'statusBarSet in the base view is set to the
  361.        // declared name of the status bar.
  362.        // Note that we do not replace the menuRightButtons.
  363.        
  364.        [
  365.            newtInfoButton,
  366.            GetLayout("New Button.t"),
  367.            GetLayout("protoCheckAllButton"),
  368.        ],
  369.      OverviewAbstract:
  370.        func(item, bBox)
  371.            begin
  372.                // create a string with date, check #, amount, and "to"
  373.                local s := ShortDateStr(item.date, 0);
  374.                s := s && $# & NumberStr(item.number);
  375.                if item.amount then
  376.                    s := s && FormattedNumberStr(item.amount, kFnBasicCurrency);
  377.                s := s && "to" && item.payee;
  378.        
  379.                // build the shape.  Take advantage of an offset transform so we can
  380.                // use the same reconciledShape or smallCheckShape for each item
  381.                // (we need the style frame anyway to set the font for the text shape.)
  382.                [
  383.                    {transform: [bbox.left, bbox.top],
  384.                     font: '{family: espy, face: 1, size: 10}},
  385.                    if item.reconciled then reconciledShape else smallCheckShape,
  386.                    MakeText(s, 20, 0, bbox.right-bbox.left-20, 15),
  387.                ];
  388.            end,
  389.      debug: "overview",
  390.      _proto: @405
  391.     };
  392.  
  393.  
  394. constant |layout_Overview.t| := overview;
  395. // End of file Overview.t
  396. // Beginning of file CheckPrintViewDef.t
  397. print :=
  398.     {symbol: kCheckPrintFormatSym,
  399.      version: 1,
  400.      name: "Single Check",
  401.      printNextPageScript:
  402.        func()
  403.        begin
  404.            return nil;        // always print one page
  405.        end,
  406.      title: "Single Check",
  407.      SetupItem:
  408.        func(item, targetInfo)
  409.                begin
  410.                    // set up the routing item if necessary
  411.                    inherited:?SetupItem(item, targetInfo);
  412.        
  413.                    local string := "Check" && targetInfo.target.number;
  414.                    if targetInfo.target.payee then
  415.                        string := string && "to" && targetInfo.target.payee;
  416.                    
  417.                    item.title := string
  418.                end;,
  419.      debug: "print",
  420.      _proto: @200
  421.     };
  422.  
  423. checkNumber :=
  424.     {viewBounds: {left: 0, top: 27, right: 0, bottom: 53},
  425.      viewJustify: 48,
  426.      text: "Static Text",
  427.      viewSetupFormScript:
  428.        func()
  429.        begin
  430.            if target.number then
  431.                text := "Check #" & FormattedNumberStr(target.number, "%0.0f");
  432.            else
  433.                text := "";
  434.        end,
  435.      debug: "checkNumber",
  436.      _proto: @218
  437.     };
  438. AddStepForm(print, checkNumber);
  439. StepDeclare(print, checkNumber, 'checkNumber);
  440.  
  441.  
  442.  
  443. date :=
  444.     {viewBounds: {left: 0, top: 0, right: 0, bottom: 26},
  445.      viewJustify: 8240,
  446.      text: "Static Text",
  447.      viewSetupFormScript:
  448.        func()
  449.        begin
  450.            if target.date then
  451.                text := "Date:" && ShortDateStr(target.date, kFormatDefault);
  452.            else
  453.                text := "";
  454.        end,
  455.      debug: "date",
  456.      _proto: @218
  457.     };
  458. AddStepForm(print, date);
  459. StepDeclare(print, date, 'date);
  460.  
  461.  
  462.  
  463. amount :=
  464.     {viewBounds: {left: 0, top: 0, right: 0, bottom: 26},
  465.      viewJustify: 8240,
  466.      text: "Static Text",
  467.      viewSetupFormScript:
  468.        func()
  469.        begin
  470.            if target.amount then
  471.                text := "Amount:" & FormattedNumberStr(target.amount, kFnBasicCurrency);
  472.            else
  473.                text := "";
  474.        end,
  475.      debug: "amount",
  476.      _proto: @218
  477.     };
  478. AddStepForm(print, amount);
  479.  
  480.  
  481.  
  482. payee :=
  483.     {viewBounds: {left: 0, top: 0, right: 0, bottom: 26},
  484.      viewJustify: 8240,
  485.      text: "Static Text",
  486.      viewSetupFormScript:
  487.        func()
  488.        begin
  489.            if target.payee then
  490.                text := "Payee:" && target.payee;
  491.            else
  492.                text := "";
  493.        end,
  494.      debug: "payee",
  495.      _proto: @218
  496.     };
  497. AddStepForm(print, payee);
  498.  
  499.  
  500.  
  501. memo :=
  502.     {viewBounds: {left: 0, top: 0, right: 0, bottom: 26},
  503.      viewJustify: 8240,
  504.      text: "Static Text",
  505.      viewSetupFormScript:
  506.        func()
  507.        begin
  508.            if target.memo then
  509.                text := "Memo:" & target.memo;
  510.            else
  511.                text := "";
  512.        end,
  513.      debug: "memo",
  514.      _proto: @218
  515.     };
  516. AddStepForm(print, memo);
  517.  
  518.  
  519.  
  520. // After Script for "print"
  521. thisView := print;
  522. // Copyright ©1995 Apple Computer, Inc. All rights reserved
  523.  
  524.  
  525.  
  526. constant |layout_CheckPrintViewDef.t| := print;
  527. // End of file CheckPrintViewDef.t
  528. // Beginning of file PrefsView.t
  529.  
  530. // Before Script for "prefs"
  531. // Copyright © 1996 by Apple Computer, Inc.  All rights reserved.
  532.  
  533.  
  534. prefs :=
  535.     {viewBounds: {left: 0, top: 0, right: 200, bottom: 88},
  536.      prefs:
  537.        // This slot will hold a reference to the application prefs frame
  538.        nil,
  539.      viewSetupFormScript:
  540.        func()
  541.        begin
  542.            // get the preferences frame and make sure that our application specific
  543.            // slot exists.  theApp is a reference to the applications base view
  544.            prefs := theApp:GetAppPreferences();
  545.            if NOT HasSlot( prefs, kAppSymbol ) then
  546.                prefs.(kAppSymbol) := Clone( kPrefsTemplate );
  547.        end,
  548.      declareSelf: 'base,
  549.      viewJustify: 80,
  550.      viewQuitScript:
  551.        // must return the value of inherited:?viewQuitScript();
  552.        func()
  553.        begin
  554.            // clean up our stuff.  We don't need to write prefs back to the soup because
  555.            // newtApp does all that for us.
  556.            theApp:SaveAppState();
  557.            RemoveSlot(self, 'prefs);
  558.            RemoveSlot(self, 'theApp);
  559.            
  560.            inherited:?viewQuitScript();        // this method is defined internally
  561.        end,
  562.      ReOrientToScreen: ROM_DefRotateFunc ,
  563.      debug: "prefs",
  564.      _proto: @179
  565.     };
  566.  
  567. _view002 :=
  568.     {title: "Checkbook Preferences",
  569.      viewBounds: {left: 0, top: 0, right: 90, bottom: 18},
  570.      _proto: @229
  571.     };
  572. AddStepForm(prefs, _view002);
  573.  
  574.  
  575.  
  576. pref1 :=
  577.     {text: "Pref 1",
  578.      viewBounds: {left: 16, top: 22, right: 192, bottom: 36},
  579.      valueChanged:
  580.        func()
  581.        begin
  582.            prefs.(kAppSymbol).pref1 := viewValue;
  583.        end,
  584.      viewSetupFormScript:
  585.        func()
  586.        begin
  587.            viewValue := prefs.(kAppSymbol).pref1;
  588.        end,
  589.      debug: "pref1",
  590.      _proto: @164
  591.     };
  592. AddStepForm(prefs, pref1);
  593.  
  594.  
  595.  
  596. pref2 :=
  597.     {text: "Pref 2",
  598.      viewBounds: {left: 16, top: 39, right: 192, bottom: 52},
  599.      valueChanged:
  600.        func()
  601.        begin
  602.            prefs.(kAppSymbol).pref2 := viewValue;
  603.        end,
  604.      viewSetupFormScript:
  605.        func()
  606.        begin
  607.            viewValue := prefs.(kAppSymbol).pref2;
  608.        end,
  609.      debug: "pref2",
  610.      _proto: @164
  611.     };
  612. AddStepForm(prefs, pref2);
  613.  
  614.  
  615.  
  616. internalStore :=
  617.     {text: "Always store new checks internally",
  618.      viewBounds: {left: 16, top: 56, right: 192, bottom: 69},
  619.      valueChanged:
  620.        func()
  621.        begin
  622.            prefs.internalStore := viewValue;
  623.        end,
  624.      viewSetupFormScript:
  625.        func()
  626.        begin
  627.            viewValue := prefs.internalStore;
  628.        end,
  629.      debug: "internalStore",
  630.      _proto: @164
  631.     };
  632. AddStepForm(prefs, internalStore);
  633.  
  634.  
  635.  
  636. _view003 := {_proto: @163};
  637. AddStepForm(prefs, _view003);
  638.  
  639.  
  640.  
  641.  
  642. constant |layout_PrefsView.t| := prefs;
  643. // End of file PrefsView.t
  644. // Beginning of file CheckBase.t
  645.  
  646. // Before Script for "checkbookApp"
  647. // Copyright ©1995 Apple Computer, Inc.  All rights reserved.
  648.  
  649.  
  650. checkbookApp :=
  651.     {prefsView: GetLayout("PrefsView.t"),
  652.      allViewDefs:
  653.        /*
  654.         * the format of this slot is {datadefSym: {viewDef1Sym: theViewDef1, viewDef2Sym: theViewDef2 ...}
  655.         *
  656.         * This slot is evaluated at *compile time* and should reference the viewDefs that need to
  657.         * be installed when the package is installed (mainly for Routing -- mail, print, fax, etc).
  658.         * They need to be installed at part-install time so that printing (or other routing) can
  659.         * occur when the application is not open.
  660.         */
  661.        
  662.        result := {};
  663.        result.(kCheckClassSym) := {};
  664.        result.(kCheckClassSym).(kCheckFrameFormatSym) := kCheckFrameFormat;                // for beam, mail, etc
  665.        result.(kCheckClassSym).(kCheckPrintFormatSym) := GetLayout("CheckPrintViewDef.t"); // for fax, print, etc...
  666.        result;,
  667.      viewQuitScript:
  668.        func()
  669.        begin
  670.            inherited:?viewQuitScript();        // this method is defined internally
  671.            RemoveSlot(self, 'viewBounds);
  672.        end,
  673.      appAll: "All Checks",
  674.      GetRouteScripts:
  675.        func(targetInfo)
  676.            begin
  677.                // merge our extraRouteScripts with the system ones
  678.                
  679.                local result := inherited:?GetRouteScripts(targetInfo);    // for future compatibility
  680.                if not result then
  681.                    result := routeScripts;
  682.                result := Clone(result);     // get writeable copy
  683.                ArrayMunger(result, 0, 0, extraRouteScripts, 0, nil);
  684.                result;
  685.            end,
  686.      viewFlags: 5,
  687.      ReOrientToScreen: ROM_DefRotateFunc,
  688.      viewBounds: {left: 0, top: 0, right: 0, bottom: 0},
  689.      appObject: ["Check", "Checks"],
  690.      dateFindSlot: 'date,
  691.      _proto: @398,
  692.      allSoups:
  693.        {
  694.            checkSoup: {
  695.                _proto: newtSoup,
  696.                soupName: "Checkbook:PIETraining",
  697.                soupIndices: [
  698.                    {structure: 'slot, path: 'date, type: 'int},
  699.                    {structure: 'slot, path: 'number, type: 'int},
  700.                    {structure: 'multiSlot, path: ['date, 'number], type: ['int, 'int]},
  701.                ],
  702.                soupQuery: {indexPath: ['date, 'number]},
  703.                soupDescr: "The Checkbook soup",
  704.                FillNewSoup: func()
  705.                    begin
  706.                        local store := if GetRoot().(kAppSymbol):GetAppPreferences().internalStore then
  707.                            GetStores()[0];
  708.                        else
  709.                            GetDefaultStore();
  710.            
  711.                        :AddEntry(self:CreateBlankEntry(), store);
  712.                    end,
  713.                CreateBlankEntry : func()
  714.                    begin
  715.                        local newNumber := 100;
  716.                        local e := theSoup:Query('{indexPath: number}):ResetToEnd();
  717.                        if e then
  718.                            newNumber := e.number + 1;
  719.                        {
  720.                            date: Time(),
  721.                            payee: nil,
  722.                            memo: nil,
  723.                            amount: 0.0,
  724.                            number: newNumber,
  725.                            reconciled: nil,
  726.                            class: kCheckClassSym,  // required for routing
  727.                        };
  728.                    end,
  729.            },
  730.        },
  731.      ReconcileChecks:
  732.        func(target, targetView)
  733.            begin
  734.                local c := GetTargetCursor(target, nil);    // works even if target is a single entry
  735.                local e := c:Entry();
  736.                local newState := NOT e.reconciled;            // go by 1st entry
  737.                while e do
  738.                    begin
  739.                        e.reconciled := newState;
  740.                        EntryChangeXmit(e, kAppSymbol);
  741.                        e := c:Next();
  742.                    end;
  743.                targetView:RedoChildren();
  744.            end,
  745.      appSymbol: kAppSymbol,
  746.      viewJustify: 240,
  747.      extraRouteScripts:
  748.        [
  749.            {
  750.                GetTitle: func(target)
  751.                    if target then
  752.                        if TargetIsCursor(target) then
  753.                            if GetTargetCursor(target, nil):Entry().reconciled then
  754.                                "Unreconcile"
  755.                            else
  756.                                "Reconcile" 
  757.                        else
  758.                            if target.reconciled then
  759.                                "Unreconcile"
  760.                            else
  761.                                "Reconcile",
  762.                icon: kReconciledIcon,
  763.                routeScript: 'ReconcileChecks,
  764.            },
  765.        ],
  766.      title: kAppName,
  767.      viewSetupFormScript:
  768.        func()
  769.        begin
  770.            inherited:?viewSetupFormScript();        // this method is defined internally
  771.            local bounds := :LocalBox();
  772.            if bounds.right > kMaxWidth or bounds.bottom > kMaxHeight then begin
  773.                self.viewBounds := Clone(self.viewBounds);
  774.                local extraH := Max(0, bounds.right - kMaxWidth);
  775.                local extraV := Max(0, bounds.bottom - kMaxHeight);
  776.                viewBounds.top := viewBounds.top + extraV div 2;
  777.                viewBounds.bottom := viewBounds.bottom - extraV div 2;
  778.                viewBounds.left := viewBounds.left + extraH div 2;
  779.                viewBounds.right := viewBounds.right - extraH div 2;
  780.            end;
  781.            local message;
  782.            if bounds.right < kMinWidth then
  783.                message := "Screen too narrow"
  784.            else if bounds.bottom < kMinHeight then
  785.                message := "Screen too short";
  786.            if message then
  787.                begin
  788.                    self.viewBounds := RelBounds(-10, -10, 0, 0);    // removed in viewQuitScript
  789.                    :Notify(kNotifyAlert, kAppName, message);
  790.                    AddDeferredSend(self, 'Close, nil);
  791.                end;
  792.        end,
  793.      statusBarSlot:
  794.        'status        // contains declared name of the status bar so layouts can use status bar.  Optional.
  795.        ,
  796.      FindSoupExcerpt:
  797.        func(item, finder)
  798.        begin
  799.            local s := ShortDateStr(item.date, 0);
  800.            s := s && $# & NumberStr(item.number);
  801.            if item.amount then
  802.                s := s && FormattedNumberStr(item.amount, kFnBasicCurrency);
  803.            s := s && "to" && item.payee;
  804.        end,
  805.      allLayouts:
  806.        {
  807.            default: GetLayout("Default View.t"),
  808.            overview: GetLayout("Overview.t"),
  809.        },
  810.      PutAwayScript:
  811.        func(item)
  812.            begin
  813.                local target := item.body;
  814.        
  815.                // Routing requires you to verify that you can handle this type of
  816.                // data before trying to put away!
  817.                if classof(target) = kCheckClassSym and not TargetIsCursor(target) then
  818.                    inherited:PutAwayScript(item);
  819.        
  820.                // we cannot handle multiple-item targets or non-checks... so return NIL
  821.                // (NIL is the result of an if stmt that has no else clause)
  822.            end,
  823.      debug: "checkbookApp",
  824.      NewCheck:
  825.        func()
  826.            begin
  827.                local newEntry := allSoups.checkSoup:CreateBlankEntry();
  828.                :AddEntry(newEntry);    // this is a newtApplication method that should/will be doc'd.
  829.            end
  830.        
  831.        /*
  832.                // This should work as well, but it has an unusual scrolling
  833.                // problem because ShowLayout currently happens at a deferred time.
  834.                
  835.                   :ShowLayout('default);
  836.        
  837.                   local store := if :GetAppPreferences().internalStore then
  838.                           GetStores()[0];
  839.                       else
  840.                           GetDefaultStore();
  841.                   local newEntry := allSoups.checkSoup:CreateBlankEntry();
  842.                   
  843.                   // if we're in a folder, put the new check in the current folder
  844.                   if labelsFilter and labelsFilter <> '_all then
  845.                       newEntry.labels := labelsFilter;
  846.                   
  847.                   allSoups.checkSoup:AddEntry(newEntry, store);
  848.                   layout.dataCursor:Goto(newEntry);
  849.                   layout:NewTarget();
  850.        */
  851.     };
  852.  
  853. status :=
  854.     {
  855.      menuRightButtons:
  856.        [
  857.            newtActionButton,
  858.            newtFilingButton,
  859.        ],
  860.      debug: "status",
  861.      _proto: @401
  862.     };
  863. AddStepForm(checkbookApp, status);
  864. StepDeclare(checkbookApp, status, 'status);
  865.  
  866.  
  867.  
  868. _view004 := {_proto: @162};
  869. AddStepForm(checkbookApp, _view004);
  870.  
  871.  
  872.  
  873.  
  874. constant |layout_CheckBase.t| := checkbookApp;
  875. // End of file CheckBase.t
  876. // Beginning of text file Install&Remove Scripts
  877. /*
  878. **      Newton Developer Technical Support Sample Code
  879. **
  880. **      Checkbook, a complete NewtApp sample
  881. **
  882. **      by Neil Rhodes, Calliope &
  883. **          Newton Developer Technical Support
  884. **
  885. **      Copyright © 1994-5 by Apple Computer, Inc.  All rights reserved.
  886. **
  887. **      You may incorporate this sample code into your applications without
  888. **      restriction.  This sample code has been provided "AS IS" and the
  889. **      responsibility for its operation is 100% yours.  You are not
  890. **      permitted to modify and redistribute the source as "DTS Sample Code."
  891. **      If you are going to re-distribute the source, we require that you
  892. **      make it clear in the source that the code was descended from
  893. **      Apple-provided sample code, but that you've made changes.
  894. */
  895.  
  896. InstallScript := func(partFrame)
  897. begin
  898.     local mainLayout := partFrame.theForm;
  899.     
  900.     partFrame.removeFrame := mainLayout:NewtInstallScript(mainLayout);
  901. end;
  902.  
  903. RemoveScript := func(partFrame)
  904. begin
  905.     (partFrame.removeFrame):NewtRemoveScript(partFrame.removeFrame);
  906. end;
  907. // End of text file Install&Remove Scripts
  908.  
  909.  
  910.  
  911.